package util;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

public class TextFormat {
	public static String getText(Map<String, Object> map, String field){
		if (map == null || map.get(field) == null || "".equals(map.get(field).toString().trim())) {
			return "";
		}
		return map.get(field).toString();
	}
	
	public static String formatToYMD(Map<String, Object> map, String field){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		if (map == null || map.get(field) == null) {
			return "";
		}
		if (map.get(field) instanceof java.util.Date) {
			return format.format(map.get(field));
		}
		return format.format(new Date(Long.valueOf(map.get(field).toString())));
	}
	
	public static String formatToYMD(Long time){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		if (time == null) {
			return "";
		}
		return format.format(new Date(time));
	}
	
	public static String formatNumber(Map<String, Object> map, String field){
		DecimalFormat format = new DecimalFormat("##,##0.00");
		if (map == null || map.get(field) == null) {
			return "";
		}
		return format.format(Double.valueOf(String.valueOf(map.get(field))));
	}
	
	public static String formatNumber(Double num){
		DecimalFormat format = new DecimalFormat("##,##0.00");
		if (num == null) {
			return "";
		}
		return format.format(num);
	}
}
